package com.tgy.cmp;

import com.tgy.Sort;

/**
 * @Author: tgy
 * @Date: 2020-10-13 14:07
 */
public class SelectionSort<E> extends Sort<E> {

    @Override
    protected void sort() {


        for (int i = elements.length - 1; i > 0; i--) {

            int maxIndex = 0;

            for (int j = 1; j <= i; j++) {

                if (compare(maxIndex,j) <= 0) {

                    maxIndex = j;
                }
            }

            if (maxIndex != i) {

                swap(maxIndex,i);
            }

        }

    }
}
